#ifndef AI_SERVICE_CLIENT_H
#define AI_SERVICE_CLIENT_H

#include <mutex>

#include "iremote_object.h"
#include "ai_service_proxy.h"
#include "singleton.h"

#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/dnn.hpp"

namespace OHOS {
namespace AIS {
class AIServiceClient : public Singleton<AIServiceClient> {
public:
    int32_t Init(std::string& modelPath, int32_t* modelId);

    int32_t Process(const int32_t modelId, PicDesc& picDesc, std::string& picData, InferResult& result); 

    int32_t DeInit();

    void ProcessDeathObserver(wptr<IRemoteObject> object);

private:
    int32_t PreProcess(PicDesc& picDesc, std::string& picData, std::string& outBuff);

    int32_t CheckInput(PicDesc& picDesc, std::string inputData) const;

    int32_t InitAIServiceClient();

    void ComputeLetterBoxAndResize(LetterBox& lb, cv::Mat &src, cv::Mat &dest);

    void HeightPad(LetterBox& lb, cv::Mat &src, cv::Mat &dest);

    void WidthPad(LetterBox& lb, cv::Mat &src, cv::Mat &dest);

    sptr<IRemoteObject::DeathRecipient> serviceDeathObserver_ = nullptr;
    sptr<IAIService> aiServiceProxy_ = nullptr;
    std::mutex clientMutex_;
};

}  // namespace AIS    
}  // namespace OHOS

#endif // AI_SERVICE_CLIENT_H